<template>
    <h1>登录页面</h1>

    <table>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="Name">
            </td>
        </tr>

        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="Pwd" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="登录" @click="UserLogin" >
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router = useRouter();

const Name = ref('');
const Pwd = ref('');

const UserLogin =()=>{
    axios({
        method:'get',
        url:'http://localhost:56767/api/Users/UserLogin',
        params:{
            name:Name.value,
            pwd:Pwd.value
        }
    })
    .then(res=>{
        console.log(res.data);
        if(res.data.CK_Code==0){
            alert(res.data.CK_Mess);//0登录成功
            router.push('/UserInfo');
        }
        else if(res.data.CK_Code==1){
            alert(res.data.CK_Mess);//用户名不存在
            return;
        }
        else if(res.data.CK_Code==2){
            alert(res.data.CK_Mess);//2账号密码不匹配
            return;
        }
        else {
            alert('登录失败');
            return;
        }
    })
    .catch(err=>{
        console.log(err);
    })
}

</script>
